package com.xiaoyg.lession01.chapter03;


/**
 * 线程执行据有随机性，
 * Thread.java类中的start()方法会随机切换上下文执行，执行run方法，
 * 必须等方法执行完才能执行别的逻辑。
 */
public class Test {

    public static void main(String[] args) {
        try {

            MyThread myThread = new MyThread();
            myThread.setName("myThread");
            myThread.start();
            for (int i = 0; i < 10 ; i++) {
                int time = (int)(Math.random()*1000);
                Thread.sleep(time);
                System.out.println("main="+Thread.currentThread().getName());
            }

        } catch (InterruptedException e){
            e.printStackTrace();
        }
    }

}
